package com.sxwl.auth.controller;

import com.sxwl.auth.service.ChatInfoService;
import com.sxwl.dto.ChatMessageDTO;
import com.sxwl.pojo.ChatRecord;
import com.sxwl.pojo.User;
import com.sxwl.vo.JsonData;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reading
 * @Description TODO
 * @Date 2020/4/14 15:56
 */
@RestController
@Slf4j
@RequestMapping("/core/service")
public class ChatInfoController {
    @Autowired
    private ChatInfoService chatInfoService;
    /**
     * 获取除了自己以外的所有在线好友
     */
    @GetMapping("/onlineuser")
    @ApiOperation(value = "获取除了自己以外的所有在线好友",notes = "获取除了自己以外的所有在线好友")
    public  JsonData getOnlineUser(@RequestHeader(value = "uid") String id){
        List<User> onlineUser = chatInfoService.getOnlineUser(id);
        return JsonData.success(onlineUser,"");
    }
    /**
     * 查询聊天记录
     */
    @GetMapping("/fcr")
    @ApiOperation(value = "查询聊天记录",notes = "查询聊天记录")
    public JsonData findChatRecord(@RequestHeader(value = "uid") String id,@RequestParam("friendid") String friendid){
        List<ChatRecord> chatRecord = chatInfoService.findChatRecord(Integer.valueOf(id),Integer.valueOf(friendid));
      return   JsonData.success(chatRecord,"");
    }

    /**
     * 查询聊天消息
     * @return
     */
    @GetMapping("/fcm")
    @ApiOperation(value = "查询聊天消息",notes = "查询聊天消息")
    public  JsonData findCharMessage(@RequestHeader(value = "uid") String id){
        ChatMessageDTO charMessage = chatInfoService.selectCharMessage(id);
        if(charMessage==null){
            return  JsonData.success(Lists.newArrayList(),"");
        }
        return   JsonData.success(charMessage,"");
    }
}
